package com.moon.game.command.guest.bag;

import com.moon.game.command.BaseCmd;
import com.moon.game.command.RequestSession;
import com.moon.game.constants.ErrorCode;
import com.moon.game.exception.GException;
import com.moon.game.resource.model.Item;
import com.moon.game.service.ItemService;
import com.moon.game.vos.ErrorMsg;

/**
 * @description 查看装备类道具
 * @author Ranger 作者 E-mail:haozi000005@163.com
 * @version 创建时间：2012-5-23 下午1:42:33
 */
public class ViewItemCmd extends BaseCmd {
	
	@Override
	protected void runOnce(RequestSession req) throws GException {
		switch (req.getStatus()) {
		case STATU_INIT:
			doInit(req);
			break;
		case STATU_CHECK:
			doCheckSelf(req);
			break;
		case STATU_RETURN:
			doResponse(req);
			break;
		default:
			break;
		}
	}
	
	@Override
	protected void doResponse(RequestSession req) throws GException {
		String[] ps = req.getClientRequest().getPs();
		if (ps == null) {
			doResponsePsError(req);
			return;
		}
		if (ps.length == 3) {
			int curPage = Integer.parseInt(ps[1]);
			int curType = Integer.parseInt(ps[2]);
			req.setVO("curr_type", curType);
			req.setVO("curr_page", curPage);
		}
		int itemId = Integer.parseInt(ps[0]);
		final Item theItem = ItemService.getItem(req.getPlayerId(), itemId);
		if (theItem == null) {
			doResponseErrorMsg(req, ErrorMsg.build(ErrorCode.ERR_RESOURCE, "找不到你要查看的道具资源！"));
			return;
		}
		req.setVO("item", theItem);
		response(req, req.getClientResponse());
	}
}
